package tgc.rj.zz.controller;

import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import tgc.rj.zz.custom.DataGridUtils;
import tgc.rj.zz.entity.Journal;
import tgc.rj.zz.form.JournalForm;
import tgc.rj.zz.service.JournalService;

@Controller
@RequestMapping(value="journal")
public class JournalController {
	@Autowired
	private JournalService journalDAO;
	
	@RequestMapping(value="all")
	public String all() {
		return "system/czrz";
	}
	
	@RequestMapping(value="/list")
	@ResponseBody
	public Object list(JournalForm form) {
		Pageable pageable = form.buildPageable();
		Page<Journal> page = null;
		if(form.getId() == null) {
			page = journalDAO.findAll(pageable);			
		}else {
			page = journalDAO.findAll(form.buildSpes(), pageable);
		}
		HashMap<String , Object> result = DataGridUtils.getPageResult(page);
		return result;
	}
}
